package main

import (
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {

	bytes, _ := ReadFromReader(os.Stdin, 1024)

	fmt.Println(bytes)

}

/**
io读取
*/
func ReadFromReader(reader io.Reader, num int) ([]byte, error) {

	bytes := make([]byte, num)
	length, err := reader.Read(bytes)

	if length > 0 {
		return bytes[:length], nil
	}
	return nil, err
}

func sampleReader() {
	var str = "sample string"
	bytes, _ := ReadFromReader(strings.NewReader(str), 1024)

	fmt.Println(bytes)
}
